﻿namespace PowerSong.UserInterface
    {
    using System.Windows;
    using System;

    /// <summary>
    /// Interaction logic for EditBannerWindow.xaml
    /// </summary>
    public partial class EditBannerWindow : Window
        {

        public BannerServiceItem Banner { get; private set; }

        private bool editing = false;

        public EditBannerWindow(BannerServiceItem banner = null)
            {
            InitializeComponent();
            this.Banner = banner;
            this.editing = banner != null;
            if (banner != null)
                {
                this.TitleTextBox.Text = banner.Title;
                this.NoticeTextBox.Text = banner.Text;
                }
            NoticeTextBox.Focus();
            }

        private void OKButton_Click(object sender, RoutedEventArgs e)
            {

            try
                {

                // Ensure a title has been specified
                if (string.IsNullOrEmpty(TitleTextBox.Text))
                    {
                    throw new Exception("Please specify a title for this scrolling notice so that it can be easily identified in the play list.");
                    }

                // Ensure scrolling notice text has been specified
                if (string.IsNullOrEmpty(NoticeTextBox.Text))
                    {
                    throw new Exception("Please specify some text for the scrolling notice.");
                    }

                // Create a new item if necessary
                if (!editing) this.Banner = new BannerServiceItem();

                // Populate banner details
                this.Banner.Title = TitleTextBox.Text;
                this.Banner.Text = NoticeTextBox.Text;

                // Close the window
                this.DialogResult = true;

                }
            catch (Exception ex)
                {
                Utilities.ShowErrorMessage("Cannot Save Scrolling Notice Details", ex.Message);
                }

            }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
            {
            this.DialogResult = false;
            }

        private void OverrideCheckBoxChanged(object sender, RoutedEventArgs e)
            {
            OverrideGrid.IsEnabled = OverrideCheckBox.IsChecked == true;
            }

        }

    }
